package com.cy.pj.goods.controller;

import com.cy.pj.goods.pojo.Goods;
import com.cy.pj.goods.server.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class GoodsController {
    @Autowired
    GoodsService goodsService;

    @GetMapping("/findGoods")
    @CrossOrigin
    public List<Goods> findAllGoods(){
        return goodsService.findAllGoods();
    }

    @RequestMapping("/deleteById/{id}")
    public void deleteById(@PathVariable Integer id){
        goodsService.deleteById(id);
    }

    @PostMapping("/save")
    @CrossOrigin
    public String save( @RequestBody Goods goods){
        goodsService.insert(goods);
        return "ok";
    }

    @RequestMapping("/selectById")
    public Goods selectById(Integer id){
        return goodsService.selectById(id);
    }

    @RequestMapping("/updateById")
    public void updateById(@RequestBody Goods goods){
        goodsService.update(goods);
    }
}
